<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	
<script src="<?php echo URL::base() ?>media/js/jquery.json-2.4.js"></script>
<style>
.date{width:113.5px}
.supplier{width:200px}
.purchaser{width:200px}
.table tbody tr td,.table thead tr th{ border:1px solid #ccc; text-align:center;}
.form-horizontal .controls{margin-left:90px;}
.form-horizontal .control-label{ width:80px;}
.asd{width:80px; text-align:right; display:inline-block; margin-right:4px;}
table tbody tr:nth-child(2n){ background-color:#f5f5f5;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('.table > tbody > tr:odd').css("background-color","#f5f5f5");
});
//重置条件
function resetdata()
{
	$("#way").val(1);
	$("#date_from").val("");
	$("#date_to").val("");
	$("#supplier").val("");
	$(".sku").val("");
	$(".purchaser").val("");
}
</script>
<html>
<body>
													
	<div class="form-horizontal">
		<div style="margin-bottom:10px">
			<span class="asd" for="input01">采购日期:</span>
            <input type="text" style="width:164px;" class="input-xlarge date"  id="date_from"  value="" readonly="true" />
			— <input style="margin-right:10px;width: 164px" type="text" class="input-xlarge date" id="date_to"  value="" readonly="true"/>
		</div>
		<div style="margin-bottom:10px">
			<span class="asd">分组条件:</span>   
				<select class="input-xlarge"  name="way" id="way" style="width: 178px">
                	<option value="1">sku</option>
                    <option value="2">采购员</option>
                    <option value="3">供应商</option>			
                    <option value="4">sku+供应商</option>
				</select>
        </div>	
        <div style="margin-bottom:10px">															
			<span class="asd" for="input01" >sku:</span>																
            <input style=" width:164px;margin-right:10px;" type="text" class="input-xlarge sku" name="" id="" value="" autocomplete="off"  />
        </div>
        <div style="margin-bottom:10px">
				<span class="asd">采购员:</span>
				<input style="width:164px;" type="text" class="input-xlarge purchaser"  name="" id="" value="">
		</div>
		
		<div style="margin-bottom:10px">
			<span class="asd" for="input01" >供应商:</span>		
			<input style=" width:164px; margin-right:10px;" type="text" class="input-xlarge supplier"  name="" id="supplier" value="">
			<button class="btn btn-info" id="search_ids">查询</button>
			<button class="btn btn-inverse" onclick="resetdata()" type="button">重置</button>
			<button class="btn btn-success" id="download_ids">下载</button>
		</div>

    </div>
<div id="table_detail" style='display:none'>
				<table id='' class="table table-bordered" style="border-collapse:collapse;">
				<thead>
								<tr style=" background-color:#4EA392;color:#fff;">
									<th>序号</th>
									<th>SKU</th>
									<th>中文名称</th>
									<th>规格</th>
									<th>储位</th>
									<th>数量</th>
									<th>未税金额</th>
									<th>税额</th>
									<th>金额</th>
									<th>运费</th>
									<th>成本合计</th>
									<th>到货量</th>
									<th>质检量</th>
									<th>入库量</th>
									<th>未交量</th>
									<th>超交量</th>
					 		</tr></thead>
							<tbody id="contents" >
							</tbody>
			</table>
</div>
<table>
<th><div style="display:none" id="more"><button class="btn btn-info" id="more_ids">查看更多</button></div></th>
<th style="display:none" id="th_total">总计:</th><td><div id="total_quantity"></div></td>
</table>
</body>
</html>
<script>
var page = 1;
$(document).ready(function(){
	$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
							$("#date_from").datepicker({  
							    onSelect:function(dateText,inst){  
							       $("#date_to").datepicker("option","minDate",dateText);  
							    }  
							});  
							$("#date_to").datepicker({  
							    onSelect:function(dateText,inst){  
							        $("#date_from").datepicker("option","maxDate",dateText);  
							    }  
							});
	$("#status").val('<?php echo isset($status)?$status:"10"; ?>');
	/*$("input[type='checkbox']").each(function(){
		if(this.checked){
			this.checked=false;
		}
	});*/
});
	$("#search_ids").click(function(){
		var date_from = $("#date_from").val();
		var date_to   = $("#date_to").val();
		var way       = $("#way").val();
		var supplier  = $("#supplier").val();
		var purchaser = $(".purchaser").val();
		var sku       = $(".sku").val();
		$.ajax({
					type:'GET',
					dataType:"html",
					url:"<?php echo URL::site() ?>report/purchase/search_total",
					async:false,
					data:{
						'date_from':date_from,
						'date_to':date_to,
						'way'    :way,
						'supplier':supplier,
						'purchaser':purchaser,
						'sku':sku
					},
					success:function(data){
						if(data==1)
						{
							$("#table_detail").hide();
							$("#more").hide();
						}else{
							page=1;
							$("#table_detail").show();
							$("#th_total").show();
							$("#contents").empty();
							$("#contents").show();
							$("#contents").append(data);
							$("#more").show();
						}
					}
				});
		$.ajax({
					type:'GET',
					dataType:"html",
					url:"<?php echo URL::site() ?>report/purchase/search_common_totals",
					async:false,
					data:{
						'date_from':date_from,
						'date_to':date_to,
						'way'    :way,
						'supplier':supplier,
						'purchaser':purchaser,
						'sku':sku
					},
					success:function(data){
						$("#total_quantity").html(data);
					}
				});
		
	});
					      //绑定未来事件
	$(document).on('click', '#more_ids', function(e){
							      	  e.preventDefault(); 
												var date_from = $("#date_from").val();
												var date_to   = $("#date_to").val();
												var way       = $("#way").val();
												var supplier  = $("#supplier").val(); 
												var purchaser = $(".purchaser").val();
												var sku = $(".sku").val();
												page++;
												url = "<?php echo URL::base();?>report/purchase/search_total?date_from="+date_from+"&date_to="+date_to+"&supplier"+supplier+"&purchaser="+purchaser+"&sku="+sku+"&page="+page+"&way="+way;
							            
							            if(url.length){
							            	get_pandian(url);
							            }
	});
function get_pandian(url){
	var dialog = art.dialog({title: '提示',icon:'question',lock: true});
	dialog.content('<p>数据查询中,请稍后...<p>');
	$.get(
    	 url,
    	   {

	    	 },
	    	 function(data){
									
	    	        //$('.mypage').clone().appendTo('#pager_links').show();
					if(data==1)
					{				
						$("#more").hide();
						dialog.close();
					}else{
					
 	    			dialog.close();
						$("#contents").append(data);
						$("#more").show();						
					}
	   	   }
    	 );
}
$("#download_ids").click(function(){
								var date_from = $("#date_from").val();
								var date_to   = $("#date_to").val();
								var supplier  = $("#supplier").val(); 
								var purchaser = $(".purchaser").val();
								var sku = $(".sku").val();
								var way = $("#way").val();
								url = "<?php echo URL::base();?>report/purchase/downloads_infos?date_from="+date_from+"&date_to="+date_to+"&supplier="+supplier+"&purchaser="+purchaser+"&sku="+sku+"&way="+way;
								window.location.href=url;
							});
$("#way").change(function(){
							var way = $("#way").val();
									$.ajax({
										type:'GET',
										dataType:"html",
										url:"<?php echo URL::site() ?>report/purchase/load_table",
										async:false,
										data:{
										'way'    :way,
										},
									success:function(data){
										$("#total_quantity").html(0);
										$("#table_detail").empty();
										$("#table_detail").html(data);
										$("#table_detail").hide();
										$("#more").hide();
								}
							});

});
</script>
